package edu.hawaii.myisern.brown.model;

/**
 * Represents a user logging into system.
 * 
 * @author Tim Fennell
 * @author Randy Cox
 */
public class User {

  /**
   * Initial value of the hash code in the attempt to create a diverse value 
   * Design attributed to "Java in a Nutshell", example 3-6, page 131, by David Flannigan.
   * result = HASH_CODE_BASE;
   * result = HASH_CODE_FACTOR * result + value;
   * result = HASH_CODE_FACTOR * result + value;
   * result = HASH_CODE_FACTOR * result + value;
   */
  private static final int HASH_CODE_BASE = 17;
  
  private Integer id;
  private String username;
  private String password;

  /** Default constructor. */
  public User() {
    // Empty
  }

  /**
   * Constructs a well formed user.
   * 
   * @param username user
   * @param password pass
   */
  public User(String username, String password) {
    this.username = username;
    this.password = password;
  }

  /**
   * Gets the ID of the person.
   * 
   * @return id of record.
   */
  public Integer getId() {
    return id;
  }

  /**
   * Sets the ID of the person.
   * 
   * @param id of record.
   */
  public void setId(Integer id) {
    this.id = id;
  }

  /**
   * Gets the username of the person.
   * 
   * @return username
   */
  public String getUsername() {
    return username;
  }

  /**
   * Sets the username of the user.
   * 
   * @param username user
   */
  public void setUsername(String username) {
    this.username = username;
  }

  /**
   * Gets the person's unencrypted password.
   * 
   * @return password pw
   */
  public String getPassword() {
    return password;
  }

  /**
   * Sets the person's unencrypted password.
   * 
   * @param password pw
   */
  public void setPassword(String password) {
    this.password = password;
  }

  /**
   * Equality is determined to be when the ID numbers match.
   * 
   * @param obj to compare.
   * @return true if equal.
   */
  public boolean equals(Object obj) {
    return (obj instanceof User) && this.id == ((User) obj).id;
  }
  
  /**
   * Hashcode
   * @return result of hascode
   */
  public int hashCode() {
    int result = HASH_CODE_BASE;
    result = HASH_CODE_BASE * result + this.id;
    result = HASH_CODE_BASE * result + this.id;
    result = HASH_CODE_BASE * result + this.id;
    return result;
  
  }

}
